﻿using DepartmentOnline.Models;
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace DepartmentOnline
{
	public partial class Groups : System.Web.UI.Page
	{
		private Pagination Pager;

        protected void Page_Load(object sender, EventArgs e)
        {
            
            if (!IsPostBack)
            {
                Pager = new Pagination()
                            {
                                BindDataAction = bindData,
                                ViewState = this.ViewState,
                                PageSize = 8
                            };
                bindData();
            }
            else
            {
                Pager = new Pagination()
                {
                    BindDataAction = bindData,
                    ViewState = this.ViewState,
                    PageSize = 8
                };
                //since the pagination controls are dynamically creating its shld be re created in each page load
                Pager.BuildPagination(pnlPager);
            }
        }

        private void bindData()
        {
            using (var context = new departmentEntities())
            {
                DataTable data = context.Groups.AsEnumerable().ToDataTable();
                Pager.BindDataWithPaging(Repeater1, data, pnlPager);
            }

        }


        public void RedirectToGroup(object sender, CommandEventArgs commandEventArgs)
        {
            Session["GroupID"] = commandEventArgs.CommandArgument;
            Response.Redirect("Group.aspx");
        }
    }
}